package com.myjunit.properties;

import java.io.InputStream;
import java.util.Properties;

/**
 * 获得属性文件中的信息
 * @author xysuncdl@cn.ibm.com
 *
 */
public class PropertiesUtil {

	public static String readValue(String filePath, String key) {

		Properties props = new Properties();
		try {
			InputStream in = Object.class.getResourceAsStream(filePath);
//			在web项目中的写法
//			InputStream in = getClass().getResourceAsStream(filePath);
			props.load(in);
			String value = props.getProperty(key);
			return value.trim();

		} catch (Exception e) {
			throw new RuntimeException("没有对应的值.");
		}
	}

	public static String getValue(String key) {
		return readValue("/ServiceNameMapping.properties", key);
	}

	public static void main(String[] args) {

		System.out.println(getValue("key"));
	}

}